package com.base.myproject.client.HR.bcode;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.base.myproject.client.busi.BaseStore;
import com.base.myproject.client.busi.BO.BusiObject;
import com.base.myproject.client.jdbc.DataSet;
import com.base.myproject.client.tools.CommandSyncContainer;
import com.base.myproject.client.tools.CommandSyncReturnObject;
import com.base.myproject.client.tools.CommandSyncsql;
import com.base.myproject.client.tools.GreetingService;
import com.base.myproject.client.tools.GreetingServiceAsync;
import com.base.myproject.client.ui.BaseJDBCPanel;
import com.extjs.gxt.ui.client.widget.Info;
import com.extjs.gxt.ui.client.widget.MessageBox;
import com.google.gwt.core.client.GWT;
import com.google.gwt.i18n.client.DateTimeFormat;
import com.google.gwt.user.client.rpc.AsyncCallback;

/**
 * 雇员工作经历 操作函数
 * ''author Administrator
 *
 */
public class EmployChange_func extends BaseJDBCPanel{
	BaseStore<BusiObject> store = new BaseStore<BusiObject>();
	int icode;
	boolean fiter=true;//!!!!控制函数得到micode
	private Bcode_EmployeeChange employee = null;
	
	public EmployChange_func(BaseStore<BusiObject> store, Bcode_EmployeeChange employee){
		this.store = store;
		this.employee = employee;
	}
	
	public EmployChange_func(){
		
	}
	
	public void init() {	
		
	}
	/**
	 * yw9.15
	 * 更新变动记录表 
	 */
	void insert_EmployChange(String msql){
		List<String> lists = new ArrayList<String>();
		lists.add(msql);
		insert_EmployChange(lists);
	}
	
	void insert_EmployChange(List<String> lists){
		CommandSyncsql csql = new CommandSyncsql();
		for (String sql : lists) {
			csql.getV().add(sql);
		}
		Command(csql);
	}
	
	void insert_EmployChange(String msql, AsyncCallback<CommandSyncReturnObject> back){
		CommandSyncsql csql = new CommandSyncsql();
		csql.getV().add(msql);
		Command(csql, back, false);
	}
	
	/**
	 * yw9.15
	 * 薪金操作
	 * bcode  人员编码
	 * salary_new  改变后的薪金
	 * salaryploy 薪金策略
	 * update_time 有效时间
	 * getsql 是否生成sql
	 */
	void opt_salary(String bcode,Double salary_new,String salaryploy,final String update_time,boolean getsql){
		String insertsql1 = "insert into bcode_Allowance (bcode,no_,startdate,amount) select '"+bcode+"' as bcode,'A01' as no_,'" + update_time + "' as startdate,(select case when baserate  >1 then baserate	 when baserate =-1 then  "+salary_new+"-isnull(positionrate, 0)-isnull(defined_salary3, 0)-isnull(defined_salary4,0) else "+salary_new+"*baserate end as amount from hr_salary_ploy where "+salary_new+">=salaryfrom and salaryto>"+salary_new+" and codename='"+salaryploy+"' )as amount";
		String insertsql2 = "insert into bcode_Allowance (bcode,no_,startdate,amount) select '"+bcode+"' as bcode,'A05' as no_,'" + update_time + "' as startdate,(select case when positionrate  >1 then positionrate 	 when positionrate =-1 then  "+salary_new+"-baserate-isnull(defined_salary3, 0)-isnull(defined_salary4,0) else "+salary_new+"*positionrate end as amount from hr_salary_ploy where "+salary_new+">=salaryfrom and salaryto>"+salary_new+" and codename='"+salaryploy+"')as amount where (select isnull(positionrate,0) from hr_salary_ploy where "+salary_new+">=salaryfrom and salaryto>"+salary_new+" and codename='"+salaryploy+"') != 0";
		String insertsql3 = "insert into bcode_Allowance (bcode,no_,startdate,amount) select '"+bcode+"' as bcode,'A06' as no_,'" + update_time + "' as startdate,(select case when defined_salary3  >1 then defined_salary3	 when defined_salary3 =-1 then  "+salary_new+"-baserate-isnull(defined_salary4, 0)-isnull(positionrate, 0) else "+salary_new+"*defined_salary3 end as amount from hr_salary_ploy where "+salary_new+">=salaryfrom and salaryto>"+salary_new+" and codename='"+salaryploy+"')as amount where (select isnull(defined_salary3,0) from hr_salary_ploy where "+salary_new+">=salaryfrom and salaryto>"+salary_new+" and codename='"+salaryploy+"') != 0";
		String insertsql4 = "insert into bcode_Allowance (bcode,no_,startdate,amount) select '"+bcode+"' as bcode,'A07' as no_,'" + update_time + "' as startdate,(select case when defined_salary4  >1 then defined_salary4 	 when defined_salary4 =-1 then  "+salary_new+"-baserate-isnull(defined_salary3, 0)-isnull(positionrate, 0) else "+salary_new+"*defined_salary4 end as amount from hr_salary_ploy where "+salary_new+">=salaryfrom and salaryto>"+salary_new+" and codename='"+salaryploy+"')as amount where (select isnull(defined_salary4,0) from hr_salary_ploy where "+salary_new+">=salaryfrom and salaryto>"+salary_new+" and codename='"+salaryploy+"') != 0";
		String updatestatus = " update bcode_Allowance set enddate = dateadd(dd,-1,'"+update_time+"'),status=1 where bcode = '"+bcode+"' and status=0 and exists (select * from hr_Salary_Item where code = no_ and salarytype = '1')";
		//下面这条语句是更新修改薪金后的bcode表中薪金字段
		String updatestatus3 = " update bcode set basesalary="+salary_new+" where bcode='"+bcode+"'";
		//手动转义逗号 
		final String s2 = "insert into bcode_Allowance (bcode,no_,startdate,amount) select ''"+bcode+"'' as bcode,''A01'' as no_,''" + update_time + "'' as startdate,(select case when baserate  >1 then baserate	 when baserate =-1 then  "+salary_new+"-isnull(positionrate, 0)-isnull(defined_salary3, 0)-isnull(defined_salary4,0) else "+salary_new+"*baserate end as amount from hr_salary_ploy where "+salary_new+">=salaryfrom and salaryto>"+salary_new+" and codename=''"+salaryploy+"'') as amount";
		final String s3 = "insert into bcode_Allowance (bcode,no_,startdate,amount) select ''"+bcode+"'' as bcode,''A05'' as no_,''" + update_time + "'' as startdate,(select case when positionrate  >1 then positionrate 	 when positionrate =-1 then  "+salary_new+"-baserate-isnull(defined_salary3, 0)-isnull(defined_salary4,0) else "+salary_new+"*positionrate end as amount from hr_salary_ploy where "+salary_new+">=salaryfrom and salaryto>"+salary_new+" and codename=''"+salaryploy+"'') as amount where (select isnull(positionrate,0) from hr_salary_ploy where "+salary_new+">=salaryfrom and salaryto>"+salary_new+" and codename=''"+salaryploy+"'') != 0";
		final String s4 = "insert into bcode_Allowance (bcode,no_,startdate,amount) select ''"+bcode+"'' as bcode,''A06'' as no_,''" + update_time + "'' as startdate,(select case when defined_salary3  >1 then defined_salary3	 when defined_salary3 =-1 then  "+salary_new+"-baserate-isnull(defined_salary4, 0)-isnull(positionrate, 0) else "+salary_new+"*defined_salary3 end as amount from hr_salary_ploy where "+salary_new+">=salaryfrom and salaryto>"+salary_new+" and codename=''"+salaryploy+"'') as amount where (select isnull(defined_salary3,0) from hr_salary_ploy where "+salary_new+">=salaryfrom and salaryto>"+salary_new+" and codename=''"+salaryploy+"'') != 0";
		final String s5 = "insert into bcode_Allowance (bcode,no_,startdate,amount) select ''"+bcode+"'' as bcode,''A07'' as no_,''" + update_time + "'' as startdate,(select case when defined_salary4  >1 then defined_salary4 	 when defined_salary4 =-1 then  "+salary_new+"-baserate-isnull(defined_salary3, 0)-isnull(positionrate, 0) else "+salary_new+"*defined_salary4 end as amount from hr_salary_ploy where "+salary_new+">=salaryfrom and salaryto>"+salary_new+" and codename=''"+salaryploy+"'') as amount where (select isnull(defined_salary4,0) from hr_salary_ploy where "+salary_new+">=salaryfrom and salaryto>"+salary_new+" and codename=''"+salaryploy+"'') != 0";
		final String s1 = "update bcode_Allowance set enddate =dateadd(dd,-1,''"+update_time+"''),status=1 where bcode = ''"+bcode+"'' and status=0 and exists (select * from hr_Salary_Item where code = no_ and salarytype = ''1'')";
		final String s7 = "update bcode set basesalary="+salary_new+" where bcode=''"+bcode+"''";
		 
		final CommandSyncsql csql = new CommandSyncsql();
		if(getsql){
			 String sql=" select max(icode) as icode  from hr_EmployeeChange where ChangeType= '薪金' and bcode='"+bcode+"' ";
			 final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT.create(com.base.myproject.client.tools.GreetingService.class);
			   greetingService2.getDataSet(sql, new AsyncCallback<DataSet>(){
				
				public void onFailure(Throwable caught) {	
				}
				
				 public void onSuccess(DataSet result) {	
					if(result.getRowCount()>0)
					{	
					    String sql1=" insert into hr_update_data (micode,SQLS,update_time,status) values ("+result.getValue(0, "icode")+",'"+s1+"','"+update_time+"',0)";
					    String sql2=" insert into hr_update_data (micode,SQLS,update_time,status) values ("+result.getValue(0, "icode")+",'"+s2+"','"+update_time+"',0)";
					    String sql3=" insert into hr_update_data (micode,SQLS,update_time,status) values ("+result.getValue(0, "icode")+",'"+s3+"','"+update_time+"',0)";
					    String sql4=" insert into hr_update_data (micode,SQLS,update_time,status) values ("+result.getValue(0, "icode")+",'"+s4+"','"+update_time+"',0)";
					    String sql5=" insert into hr_update_data (micode,SQLS,update_time,status) values ("+result.getValue(0, "icode")+",'"+s5+"','"+update_time+"',0)";
				//	    String sql6=" insert into hr_update_data (micode,SQLS,update_time,status) values ("+result.getValue(0, "icode")+",'"+s6+"','"+update_time+"',0)";
					    String sql7=" insert into hr_update_data (micode,SQLS,update_time,status) values ("+result.getValue(0, "icode")+",'"+s7+"','"+update_time+"',0)";

					    csql.getV().add(sql1);
					    csql.getV().add(sql2);
					    csql.getV().add(sql3);
					    csql.getV().add(sql4);
					    csql.getV().add(sql5);
					//    csql.getV().add(sql6);
					    csql.getV().add(sql7);
					    Command(csql);
					} 
				}
			});	    
		}else{
		csql.getV().add(updatestatus);
		csql.getV().add(insertsql1);
		csql.getV().add(insertsql2);
		csql.getV().add(insertsql3);
		csql.getV().add(insertsql4);
	//	csql.getV().add(updatestatus2);
		csql.getV().add(updatestatus3);
		Command(csql);
		}
	}
	/**
	 * yw9.16  部门变动
	 * bcode
	 * f_id
	 * u_id
	 * Identifier
	 * update_time
	 */
	void opt_department(String bcode,String f_id,String u_id,String Identifier,final String update_time,boolean getsql){
		String employno=Identifier+bcode;
		final String sql1=" update bcode set systemid='"+f_id+"',up_department='"+u_id+"',Identifier='"+Identifier+"' where bcode='"+bcode+"'";
		final String sql2=" update bcode_job set employno='"+employno+"' where bcode='"+bcode+"'";
		final String s1=" update bcode set systemid=''"+f_id+"'',up_department=''"+u_id+"'',Identifier=''"+Identifier+"'' where bcode=''"+bcode+"''";
		final String s2=" update bcode_job set employno=''"+employno+"'' where bcode=''"+bcode+"''";
		final CommandSyncsql csql = new CommandSyncsql();
		if(getsql){
			String sql=" select max(icode) as icode  from hr_EmployeeChange where bcode='"+bcode+"' ";
			 final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT.create(com.base.myproject.client.tools.GreetingService.class);
			   greetingService2.getDataSet(sql, new AsyncCallback<DataSet>(){
				
				public void onFailure(Throwable caught) {	
				}
			
				 public void onSuccess(DataSet result) {	
					if(result.getRowCount()>0)					{	
					String sql3=" insert into hr_update_data (micode,SQLS,update_time,status) values ("+result.getValue(0, "icode")+",'"+s1+"','"+update_time+"',0)";
					String sql4=" insert into hr_update_data (micode,SQLS,update_time,status) values ("+result.getValue(0, "icode")+",'"+s2+"','"+update_time+"',0)";
					csql.getV().add(sql3);
				    csql.getV().add(sql4);
				    Command(csql, null, true);
					}
				}
			});			
		}else{

			csql.getV().add(sql1);
		    csql.getV().add(sql2);
		    Command(csql, null, true);
		}
		
	}
	/**
	 * yw 9.16 职级操作
	 */
	void opt_employleve(String bcode,String employlevel,final String update_time,boolean getsql){
		String sql1=" update bcode_job set employlevel='"+employlevel+"' where bcode='"+bcode+"'";
		final String s1=" update bcode_job set employlevel=''"+employlevel+"'' where bcode=''"+bcode+"''";
		final CommandSyncsql csql = new CommandSyncsql();
		if(getsql){
			String sql=" select max(icode) as icode  from hr_EmployeeChange where bcode='"+bcode+"' ";
			 final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT.create(com.base.myproject.client.tools.GreetingService.class);
			   greetingService2.getDataSet(sql, new AsyncCallback<DataSet>(){
				
				public void onFailure(Throwable caught) {	
				}
				
				 public void onSuccess(DataSet result) {	
					if(result.getRowCount()>0)					{	
					String sql1=" insert into hr_update_data (micode,SQLS,update_time,status) values ("+result.getValue(0, "icode")+",'"+s1+"','"+update_time+"',0)";
				 
					csql.getV().add(sql1);
				    Command(csql, null, true);
					}
				}
			});			
		}else{
			csql.getV().add(sql1);
		    Command(csql, null, true);
		}
	}
	/**
	 * yw 9.16 职位操作
	 */
	void opt_employinnertitle(String bcode,String employoutertitle,final String update_time,boolean getsql){
		String sql1=" update bcode_job set employinnertitle='"+employoutertitle+"' where bcode='"+bcode+"'";
		final String s1=" update bcode_job set employinnertitle=''"+employoutertitle+"'' where bcode=''"+bcode+"''";
		final CommandSyncsql csql = new CommandSyncsql();
		if(getsql){
			String sql=" select max(icode) as icode  from hr_EmployeeChange where bcode='"+bcode+"' ";
			 final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT.create(com.base.myproject.client.tools.GreetingService.class);
			   greetingService2.getDataSet(sql, new AsyncCallback<DataSet>(){
				
				public void onFailure(Throwable caught) {	
				}
				
				 public void onSuccess(DataSet result) {	
					if(result.getRowCount()>0)					{	
					String sql1=" insert into hr_update_data (micode,SQLS,update_time,status) values ("+result.getValue(0, "icode")+",'"+s1+"','"+update_time+"',0)";
				    csql.getV().add(sql1);
				    Command(csql, null, true);
					}
				}
			});			
		}else{
			csql.getV().add(sql1);
		    Command(csql, null, true);
		}
	}
	/**
	 * yw 9.16 离职操作
	 */
	void opt_separation(String bcode, String leaveReason,final String update_time,boolean getsql){
		DateTimeFormat format = DateTimeFormat.getFormat("yyyy-MM-dd");
		Date date = format.parse(update_time);
		long time = date.getTime() + 86400000;  //让该日期加一天
		date = new Date(time);  //得到加了一天后的日期
		String across_date = format.format(date);
		String sql1=" update bcode_job set leavereason = '" + leaveReason + "', employstatus='离职',lastjobdate = '" + update_time + "',Resignationdate='"+across_date+"' where bcode='"+bcode+"'";	
		final String s1=" update bcode_job set leavereason = ''" + leaveReason + "'', employstatus=''离职'',lastjobdate = ''" + update_time + "'',Resignationdate=''"+across_date+"'' where bcode=''"+bcode+"''";
		final CommandSyncsql csql = new CommandSyncsql();
		
		final String sql11 = "delete from hr_hostel_bcode where bcode='"
			+ bcode
			+ "'";
		final String sql22 = "delete from hr_wardrode_bcode where bcode='"
			+ bcode
			+ "'";
		final String sql33 = "update hr_wardrobe set usedcount=0 where code=(select upcode from hr_wardrode_bcode where bcode='"
			+ bcode
			+ "')";
		
		final String updateSql = updateSql(bcode, "离职");
		if(getsql){
			String sql=" select icode from hr_EmployeeChange where whether_continue = 0 and changeType = '离职' and bcode = '" + bcode + "'";
			 final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT.create(com.base.myproject.client.tools.GreetingService.class);
			   greetingService2.getDataSet(sql, new AsyncCallback<DataSet>(){
				   
				public void onFailure(Throwable caught) {	
				}
				
				 public void onSuccess(DataSet result) {	
					String sql1 =" insert into hr_update_data (micode,SQLS,update_time,status) values ("
						+ result.getValue(0, "icode") +",'"+s1+"','"+update_time+"',0)";
					String sql2 = " insert into hr_update_data (micode,SQLS,update_time,status) values ("
						+ result.getValue(0, "icode") +",'"+updateSql.replaceAll("'", "''")+"','"+update_time+"',0)";
					String sql111 = " insert into hr_update_data (micode,SQLS,update_time,status) values ("
						+ result.getValue(0, "icode") +",'"+sql11.replaceAll("'", "''")+"','"+update_time+"',0)";
					String sql222 = " insert into hr_update_data (micode,SQLS,update_time,status) values ("
						+ result.getValue(0, "icode") +",'"+sql22.replaceAll("'", "''")+"','"+update_time+"',0)";
					String sql333 = " insert into hr_update_data (micode,SQLS,update_time,status) values ("
						+ result.getValue(0, "icode") +",'"+sql33.replaceAll("'", "''")+"','"+update_time+"',0)";
					csql.getV().add(sql1);
					csql.getV().add(sql2);
					csql.getV().add(sql111);
					csql.getV().add(sql222);
					csql.getV().add(sql333);
				    Command(csql, null, true);
				}
			});
			
		} else {
			csql.getV().add(sql11);
			csql.getV().add(sql22);
			csql.getV().add(sql33);
			csql.getV().add(sql1);
			csql.getV().add(updateSql);
			Command(csql, null, true);
		}
	}
	/**
	 * yw 9.16 离职恢复操作
	 */
	void opt_back_separation(String bcode,String before,String update_time,String icode){
		Date df_date = new Date();
		java.util.Date currentTime = new java.util.Date();
		df_date.setYear(currentTime.getYear());
		df_date.setMonth(currentTime.getMonth());
		df_date.setDate(currentTime.getDate());
		
		String month=String.valueOf((df_date.getMonth()+1));
		if(month.length()<2){
			month="0"+month;
		}
		String nar_str=(df_date.getYear()+1900)+"-"+month+"-"+df_date.getDate();
		
		Date nnow=change_to_date(nar_str);
		
		Date ad=change_to_date(update_time);//变动表中的有效日期
		CommandSyncsql csql = new CommandSyncsql();
		
		if(nnow.before(ad)){//有效日期大于当前日期
			String sql3="delete from hr_update_data where micode ="+icode;
			String sql4="delete from hr_EmployeeChange where icode ="+icode;
			csql.getV().add(sql3);

			csql.getV().add(sql4);
			Command(csql, null, true);
		}else{
			String sql1 = "delete from hr_EmployeeChange where  changetype='离职' and  bcode='" + bcode + "'";
			String sql2="update bcode_job set leavereason=null, employstatus='"+before+"',Resignationdate=null,lastjobdate = null where bcode='"+bcode+"'";
			csql.getV().add(sql1);
			csql.getV().add(sql2);
		    Command(csql, null, true);		
		}
			
	}
	/**
	 * yw 9.16  转正操作''
	 */
	void opt_Regularization(String bcode,String after,boolean yx,final String update_time,boolean getsql){
		String sql1="";
		String s1="";
		if (after.equals("正式工")) {
			sql1="update bcode_job set jobtype='"+after+"',Regularizationdate='"+update_time+"' where bcode='"+bcode+"'";
			s1="update bcode_job set jobtype=''"+after+"'',Regularizationdate=''"+update_time+"'' where bcode=''"+bcode+"''";
		} else {
			if(yx){//是否选中延续
				//选中延续后不需要跟新入职日期
				sql1="update bcode_job set jobtype='"+after+"' where bcode='"+bcode+"'";
				s1="update bcode_job set jobtype=''"+after+"'' where bcode=''"+bcode+"''";
			}else{
				//没有选中 则表示跟新入职日期为 当前填写的有效日期
				sql1="update bcode_job set jobtype='"+after+"',entrydate='"+update_time+"' where bcode='"+bcode+"'";
				s1="update bcode_job set jobtype=''"+after+"'',entrydate=''"+update_time+"'' where bcode=''"+bcode+"''";
			}
		}
		
		final String s2=s1;
		final CommandSyncsql csql = new CommandSyncsql();
		final String updateSql = updateSql(bcode, "转正");
		if(getsql){
			String sql=" select icode from hr_EmployeeChange where whether_continue = 0 and changeType = '转正' and bcode = '" + bcode + "'";
			 final com.base.myproject.client.tools.GreetingServiceAsync greetingService2 = GWT.create(com.base.myproject.client.tools.GreetingService.class);
			   greetingService2.getDataSet(sql, new AsyncCallback<DataSet>(){
				   
				public void onFailure(Throwable caught) {	
				}
				
				 public void onSuccess(DataSet result) {	
					if(result.getRowCount()>0)					{	
					String sql1=" insert into hr_update_data (micode,SQLS,update_time,status) values ("+ result.getValue(0, "icode")+",'"+s2+"','"+update_time+"',0)";
					String sql2 = " insert into hr_update_data (micode,SQLS,update_time,status) values ("
						+ result.getValue(0, "icode") +",'"
						+ updateSql
								.replaceAll(
										"'",
										"''")
						+ "','"
						+ update_time
						+ "',0)";
					csql.getV().add(sql1);
					csql.getV().add(sql2);
				    Command(csql, null, true);
					}
				}
			});			
		}else{
			csql.getV().add(sql1);
			csql.getV().add(updateSql);
		    Command(csql, null, true);
		}
	}
	
	private String updateSql(String bcode, String type){
		String sql = "update hr_EmployeeChange set whether_continue = 1 where whether_continue = 0 and bcode = '" + bcode + "' and ChangeType = '" + type + "'";
		return sql;
	}
	
	/**
	 * yw 9.16 取消转正
	 */
	void back_Regularization(String bcode,String icode,String before,Date now,String avadate){
		Date ad=change_to_date(avadate);//变动表中的有效日期
		String month=String.valueOf((now.getMonth()+1));
		if(month.length()<2){
			month="0"+month;
		}
		String nar_str=(now.getYear()+1900)+"-"+month+"-"+now.getDate();
		
		Date nnow=change_to_date(nar_str);
		CommandSyncsql csql = new CommandSyncsql();

		if(nnow.before(ad)){//有效日期大于当前日期
			String deleteSql = "delete from hr_EmployeeChange where icode ="+icode;
			String sql3="delete from hr_update_data where micode ="+icode;
			csql.getV().add(sql3);
			csql.getV().add(deleteSql);
		}else{
			String deleteSql = "delete from hr_EmployeeChange where icode ="+icode;
			String udpateSql = "update bcode_job set jobtype = '" + before + "',Regularizationdate = null where bcode = '" + bcode + "'";
			csql.getV().add(deleteSql);
			csql.getV().add(udpateSql);
		}
		Command(csql, null, true);
	}
	/**
	 * yw 9.16  再入职 操作
	 * 
	 */
	void Re_Regularization(String bcode,boolean yx,final String update_time,String availableDate,boolean getsql){
		String sql1="";
		String s1="";
		
		if(yx){//是否选中延续:是
			//选中延续后不需要跟新入职日期
			sql1="update bcode_job set Time_interval=Time_interval+(select DATEDIFF(d,'"+availableDate+"','"+update_time+"')), employstatus='在职',Resignationdate=null,lastjobdate = null where bcode='"+bcode+"'";
			s1="update bcode_job set Time_interval=Time_interval+(select DATEDIFF(d,'"+availableDate+"','"+update_time+"')), employstatus=''在职'',Resignationdate=null,lastjobdate = null where bcode=''"+bcode+"''";
		}else{
			//没有选中 则表示跟新入职日期为 当前填写的有效日期entrydate
			sql1="update bcode_job set Time_interval=0, employstatus='在职',Resignationdate=null,lastjobdate = null,entrydate='"+update_time+"', regularizationdate = null where bcode='"+bcode+"'";
			s1="update bcode_job set Time_interval=0,employstatus=''在职'',Resignationdate=null,lastjobdate = null,entrydate=''"+update_time+"'', regularizationdate = null where bcode=''"+bcode+"''";
		}
		String updateSql = updateSql(bcode, "再入职");
		
		CommandSyncsql csql = new CommandSyncsql();
		if(getsql){	
			s1=" insert into hr_update_data (SQLS,update_time,status) values ('"+s1+"','"+update_time+"',0)";
			updateSql =" insert into hr_update_data (SQLS,update_time,status) values ('"+updateSql
			.replaceAll(
					"'",
					"''")+"','"+update_time+"',0)";
			csql.getV().add(s1);
			csql.getV().add(updateSql);
		}else{
			csql.getV().add(sql1);
			csql.getV().add(updateSql);
		}
		Command(csql, null, true);
	}
	
	/**
	 * yw 9.15 
	 * 执行更新语句
	 */
	void Command(CommandSyncsql c, AsyncCallback<CommandSyncReturnObject> asyn, final boolean refresh){  //s控制是那种操作
		AsyncCallback<CommandSyncReturnObject> back = new AsyncCallback<CommandSyncReturnObject>() {
			public void onFailure(
					Throwable caught) {
				MessageBox.alert("错误",
						"网络连接失败", null);	
			}
			public void onSuccess(
					CommandSyncReturnObject result) {
				if (result.isB()) {
			    	  Info.display("", "对员工数据操作成功!");
			    	  if (refresh) {
			    		  store.reload();
			    		  employee.getEmployeeChange(employee.bcode, employee.bname);
			    	  }
				}
				else{
					MessageBox.alert("错误",
							"错误，错误代码"+result.getMessage(), null);
					
				}
			}
		};
		if (asyn == null) {
			asyn = back;
		}
		CommandSyncsql csql = new CommandSyncsql();
		csql=c;
		if(csql.getV().size()>0){
			 GreetingServiceAsync greetingService = GWT
				.create(GreetingService.class);
			 CommandSyncContainer list = new CommandSyncContainer();
			 list.add(csql);
			 greetingService
				.SendCommandSync(
						list,
						asyn);
		}	 
	}
	
	void Command(CommandSyncsql c){
		Command(c, null, false);
	}
	
	private boolean Command_esc(List<String> lists) {
		CommandSyncsql csql = new CommandSyncsql();// 执行sql命令
		for (String sql : lists) {
			csql.getV().add(sql);
		}
		if (csql.getV().size() <= 0) {
			return false;
		} else {
			CommandSyncContainer list = new CommandSyncContainer();// 可以添加的命令
			list.add(csql);

			GreetingServiceAsync greetingService = GWT
					.create(GreetingService.class);
			greetingService.SendCommandSync(list,
					new AsyncCallback<CommandSyncReturnObject>() {
						@Override
						public void onFailure(Throwable caught) {
							MessageBox.alert("错误", "网络连接失败", null);
						}

						@Override
						public void onSuccess(CommandSyncReturnObject result) {
							if (result.isB()) {
								
							} else {
								MessageBox.alert("错误", "错误，错误代码"
										+ result.getMessage(), null);

							}
						}
					});
		}
		return true;
	}
	
	public void Command_esc(String sql){  //s控制是那种操作
		List<String> list = new ArrayList<String>();
		list.add(sql);
		Command_esc(list);
	}
	/**********
	 * 传入一个日期字符串 2010-09-09 返回一个日期对象
	 * ***********/
	Date change_to_date(String strdate){//2010-09-15
		java.util.Date currentTime = new java.util.Date();
		Date df_date=new Date();
		int year=Integer.parseInt(strdate.substring(0, 4));
		int month=Integer.parseInt(strdate.substring(5, 7));
		int day = 0;
		if (strdate.length() > 10) {
			day=Integer.parseInt(strdate.substring(8, 10));
		} else {
			day=Integer.parseInt(strdate.substring(8));
		}
		df_date.setYear(year);
		df_date.setMonth(month);
		df_date.setDate(day);
		return df_date;
	}		

}
